'use strict';
const CommonService = require("./CommonService");
const ICacheService = require("./cache/ICacheService");

/**
 *
 */
class MiniAppService extends CommonService {


    /**
     *
     * @param appid
     * @param sercet
     * @param cacheService
     */
    constructor(appid, sercet, cacheService) {
        super(appid, sercet);
        //数据保存的的地方
        this.initCacheService(cacheService);
    }

    /**
     * 设置缓存服务类
     * @param cacheService {ICacheService}
     */
    initCacheService(cacheService) {
        //设置的缓存服务
        if (cacheService instanceof ICacheService) {
            this.cacheService = cacheService;
        }

        //否则默认的
        this.cacheService = ICacheService;
    }

    /**
     * 获取认证服务
     * @return {AuthService}
     */
    getAuthService() {
        const authService = require('./auth/AuthService');
        authService.appid = this.appid;
        authService.cacheService = this.cacheService;
        authService.secret = this.secret;
        return authService;
    }

    /**
     *
     */
    getAnalysisService() {
        const analysisService = require('./analysis/AnalysisService');
        analysisService.cacheService = this.cacheService;
        analysisService.appid = this.appid;
        analysisService.secret = this.secret;
        return analysisService;
    }
}

module.exports = MiniAppService




